<?php namespace Core\Myapp\Helper\Log;

class Logger
{
    protected static $_file = 'system.log';
    protected static $_folder = 'log';

    protected function checkLogConfig()
    {
        return true;
    }
    public function write($message, $file = null, $line = null)
    {
        if($this->checkLogConfig())
        {
            try {
                $logDir  = BP . DS . 'etc' . DS . 'log';
                $logFile = $logDir . DS . self::$_file;

                if (!is_dir($logDir)) {
                    mkdir($logDir);
                    chmod($logDir, 0777);
                }

                if (!file_exists($logFile)) {
                    file_put_contents($logFile, '');
                    chmod($logFile, 0777);
                }
                $message = date("Y-m-d H:i:s") .' - '.$message;
                $message .= is_null($file) ? '' : " in $file";
                $message .= is_null($line) ? '' : " on line $line";
                $message .= "\n";
                return file_put_contents( $logFile, $message, FILE_APPEND );
            }
            catch (\Exception $e)
            {
                echo $e->getMessage();
            }
        }
    }
}